package cn.wolfcode.edu.web.controller;

import cn.wolfcode.edu.domain.Test;
import cn.wolfcode.edu.query.ClientQueryObject;
import cn.wolfcode.edu.query.QueryObject;
import cn.wolfcode.edu.query.TestQueryObject;
import cn.wolfcode.edu.service.ITestService;
import cn.wolfcode.edu.util.JsonResult;
import cn.wolfcode.edu.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("test")
public class TestController {

    @Autowired
    private ITestService testService;

    //定位测试管理界面
    @RequestMapping("")
    public String gotoClientPage(){
        return "client/test";
    }

    //给test_datagrid 传递数据
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(TestQueryObject qo){
        PageResult pageResult = testService.query(qo);
        return pageResult;
    }

    //新增考试预约
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Test test){
        try {
            testService.save(test);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult("预约失败");
        }
    }

    //批阅
    @RequestMapping("audit")
    @ResponseBody
    public JsonResult audit(Test test){
        try {
            testService.audit(test);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult("通过失败");
        }
    }
    //删除
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long testId){
        try {
            testService.delete(testId);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult("删除失败");
        }
    }
}
